package com.mx.recycle_demo.activity

import android.os.Bundle
import android.view.Gravity
import android.widget.RadioGroup
import androidx.appcompat.app.AppCompatActivity
import com.mx.recycle_demo.R
import com.mx.recycle_demo.adapt.SimpleImgAdapt
import com.mx.recycleview.utils.Log
import com.mx.recycleview.utils.dp2px
import kotlinx.android.synthetic.main.activity_banner_view.*

class BannerActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_banner_view)
        val list = arrayListOf<Int>()
        val adapter = SimpleImgAdapt(list)
        bannerView.setIndicateGravity({ button ->
            button.setBackgroundResource(R.drawable.bg_cb)
            val lp = (button.layoutParams as RadioGroup.LayoutParams)
            lp.width = dp2px(10f)
            lp.height = dp2px(2f)
            lp.leftMargin = dp2px(5f)
        }, Gravity.LEFT, dp2px(5f))
        bannerView.startAutoPlay(4)
        bannerView.setAdapt(adapter)
        bannerView.setOnSelectListener {
            Log("setOnSelectListener = $it")
        }

        list.addAll(
            arrayOf(
                R.mipmap.item1, R.mipmap.item2, R.mipmap.item3, R.mipmap.item4,
                R.mipmap.item5, R.mipmap.item6
            )
        )
        adapter.notifyDataSetChanged()

        adapter.setItemClick { position, record ->
            list.add(position, record)
            adapter.notifyDataSetChanged()
        }
//        bannerView.setLoop(false)
    }
}